#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool peoples[100086] = { false };
string names[100086];

int main(int argc, char const *argv[])
{
    int n, m, i, j, b, t, p;
    cin >> n >> m;
    for (i = 0; i < n; i++)
    {
        cin >> b >> names[i];
        peoples[i] = b == 1;
    }

    p = 0;
    for (i = 0; i < m; i++)
    {
        cin >> b >> t;
        if (b)
        {
            if (peoples[p])
            {
                p -= t;
            }
            else
            {
                p += t;
            }
        }
        else
        {
            if (peoples[p])
            {
                p += t;
            }
            else
            {
                p -= t;
            }
        }
        if (p < 0)
        {
            p = n + p;
        }
        else if (p > n - 1)
        {
            p = p % n;
        }
    }

    cout << names[p];    
    
    return 0;
}
